Everything Totally Explained


Ask & we'll explain, totally!
Lookup table
Totally Explained


  FOR SALE!Either this or the left-hand panel are available for just $19.95 per
day, or you can have both for only $34.95! Contact us for details.  


View this entry using RSS

Everything about Lookup Table totally explained

In computer science, a lookup table is a data structure, usually an array or associative array, used to replace a runtime computation with a simpler array indexing operation. The speed gain can be significant, since retrieving a value from memory is often faster than undergoing an expensive computation. A classic example is a trigonometry calculation for example calculating the sine of a value every time. Such operation can substantially slow some applications. To avoid this, the application can take a few seconds when it first starts to precalculate the sine of a number of values, for example for each whole number of degrees. Later, when the program wants the sine of a value, it uses the lookup table to retrieve the sine of a nearby value from a memory address instead of calculating it using a mathematical formula. Lookup tables are also used by mathematics co-processors; an error in a lookup table was responsible for Intel's infamous floating-point divide bug.
   Before the advent of computers, similar tables were used by people to speed up hand calculations. Particularly prevalent were tables of values for trigonometry, logarithms, and statistical density functions.
   Functions of a single variable (such as sine and cosine) may be implemented by a simple array - functions involving two or more variables require multidimensional array indexing techniques. Hence, one might replace a function to calculate xy for a limited range of x and y values with a two-dimensional array power[x][y]. Functions that have more than one result may be implemented with lookup tables that are arrays of structures.
   There are intermediate solutions that use tables in combination with a small amount of computation, often using interpolation. This allows better accuracy for values falling between two precomputed values. This requires slightly more time but can greatly enhance accuracy in applications that require it. Depending on the values being precomputed, this technique can also be used to shrink the lookup table size while retaining about the same accuracy.
   In image processing, lookup tables are often called LUTs and give an output value for each of a range of index values. One common LUT, called the colormap or palette, is used to determine the colors and intensity values with which a particular image will be displayed. Windowing in computed tomography refers to a related concept.
   It's important to note that, while often effective, lookup tables can result in a severe penalty if the computation it replaces is relatively simple, not only because retrieving the result from memory may require more time, but also because it may increase memory requirements and pollute the cache. If the table is large, each table access will almost certainly cause a cache miss. This is increasingly becoming an issue as processors outrace memory. A similar issue appears in rematerialization, a compiler optimization. In some environments, such as the Java programming language, table lookups can be even more expensive due to mandatory bounds-checking involving an additional comparison and branch for each lookup.
   There are two fundamental limitations on when it's possible to construct a lookup table for a problem. One is the amount of memory that's available: one can't construct a lookup table larger than the space available for the table, although it's possible to construct disk-based lookup tables at the expense of lookup time. The other restriction is the time required to compute the table values in the first instance — although this usually needs to be done only once, if it takes a prohibitively long time, it may make the use of a lookup table an inappropriate solution.

Examples

Computing sines

Most computers, which only perform basic arithmetic operations, can't directly calculate the sine of a given value. Instead, they use the CORDIC algorithm or a complex formula such as the following Taylor series to compute the value of sine to a high degree of precision:
» operatorname Note that even this simple algorithm can be too slow now, because the code runs faster from the cache of modern processors, but lookup tables don't fit well in caches and can cause a slower access to memory (in addition it requires computing addresses within a table, to perform the four lookups needed). On a 64-bit platform, the lookup table, if used, can't be appropriately increased in size as it would exhaust processor caches, and if the lookup table is used to count bits by group of 8, then eight successive lookups are needed and this slows down the performance.

Caches

Storage caches (including disk caches for files, or processor caches for either for code or data) work also like a lookup table: the table is built with very fast memory instead of being stored on slower external memory, and maintains two pieces of data for a subrange of bits composing an external memory (or disk) address (notably the lowest bits of any possible external address):
  • one piece (the tag) contains the value of the remaining bits of the address; if these bits match with those from the memory address to read or write, then the other piece contains the cached value for this address.
  • the other piece maintains the data associated to that address. A single (fast) lookup is performed to read the tag in the lookup table at the index specified by the lowest bits of the desired external storage address, and to determine if the memory address is hit by the cache. When a hit is found, no access to external memory is needed (except for write operations, where the cached value may need to be updated asynchronously to the slower memory after some time, or if the position in the cache must be replaced to cache another addresss).

Hardware LUTs

In digital logic, an n-bit lookup table can be implemented with a multiplexer whose select lines are the inputs of the LUT and whose inputs are constants. An n-bit LUT can encode any n-input Boolean function by modeling such functions as truth tables. This is an efficient way of encoding Boolean logic functions, and LUTs with 4-6 bits of input are in fact the key component of modern FPGAs.

Further Information

Get more info on 'Lookup Table'.


External Link Exchanges

Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:

    <a href="http://lookup_table.totallyexplained.com">Lookup table Totally Explained</a>

Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
   As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned.



Copyright © 2007-8 totallyexplained.com | Licensed under the GNU Free Documentation License | Site Map
This article contains text from the Wikipedia article Lookup table (History) and is released under the GFDL | RSS Version